<template>
  <div id="slider" class="mui-slider">
    <div
      id="sliderSegmentedControl"
      class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted"
    >
      <div class="mui-scroll">
        <span
          :class="['mui-control-item', item.id == 0 ? 'mui-active' : '']"
          v-for="item in category"
          :key="item.id" @click="changeCategory(item.id)"
        >{{item.title}}</span>
      </div>
    </div>
    <ul class="lazyul">
      <router-link tag="li" v-for="item in photolist" :key="item.id" :to="'/home/photoinfo/'+item.id">
        <img src="../../images/img.png" />
        <div class="info">
          <h1 class="info-title">{{item.title}}</h1>
          <div class="info-content">{{item.zhaiyao}}</div>
        </div>
      </router-link>
    </ul>
  </div>
</template>
<script>
import mui from "../../lib/mui/js/mui.min.js";

export default {
  data() {
    return {
      category: [],
      photolist: []
    };
  },
  methods: {
    getPhotoCategory() {
      this.$http.get("/api/getimgcategory").then(result => {
        console.log(result.data.message);
        this.category.unshift({ title: "全部", id: 0 });
        this.category = this.category.concat(result.data.message);
      });
    },
    getPhotoByCategory(id) {
      this.$http.get("/api/getimages/" + id).then(result => {
        console.log(result.data.message);
        this.photolist = result.data.message;
      });
    },
    changeCategory(id){
       this.$http.get("/api/getimages/" + id).then(result => {
        console.log(result.data.message);
        this.photolist = result.data.message;
      });
    }
  },
  created() {
    this.getPhotoCategory();
    this.getPhotoByCategory(0);
  },
  mount() {
    mui(".mui-scroll-wrapper").scroll({
      deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
    });
  },
  props:["id"]
};
</script>
<style lang="scss">
.mui-slider {
  touch-action: pan-x;
}
.lazyul {
  margin: 0;
  padding: 10px;

  li {
    background-color: #ccc;
    text-align: center;
    box-shadow: 0 0 7px gray;
    position: relative;
    & + li {
      margin-top: 10px;
    }
    img {
      vertical-align: middle;
      width: 100%;
    }

    img[lazy=":loading"] {
      width: 40px;
      height: 300px;
      margin: auto;
    }
  }
}
.info {
  position: absolute;
  bottom: 0;
  color: #fff; 
  max-height: 88px;
  background-color: rgba(15, 15, 15, 0.904);
  .info-title {
    font-size: 14px;
  }
  .info-content {
    font-size: 13px;
    text-align: left;
   text-indent: 2em;
  }
}
</style>